/**
 * Copyright:  Copyright (c) 2013
 *
 * @FileName		: ProfitAndLossTeamAction.java
 * @PageName		: 손익현황 - 팀별
 * @Date			: 오전 11:17:43
 * @LastModifier	: 최경민
 * @LastModifyDate	: 
 * @LastModifier	: 
 * Change history	:
 */
package com.pulp.management.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.pulp.management.model.ManagementInfo;
import com.pulp.management.service.ManagementService;

/**
 * @author 최경민
 * 
 */
public class ProfitAndLossTeamAction extends ActionSupport {
	private static final long serialVersionUID = 1023740792277291894L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(ProfitAndLossTeamAction.class);

	private String errorCode = "";
	private String page;
	private String total;

	private List<ManagementInfo> profitAndLossTeamYearList = null;
	private List<ManagementInfo> profitAndLossTeamMonthList = null;
	private List<ManagementInfo> profitAndLossTeamDateList = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		ProfitAndLossTeamAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the total
	 */
	public String getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(String total) {
		this.total = total;
	}

	/**
	 * @return the profitAndLossTeamYearList
	 */
	public List<ManagementInfo> getProfitAndLossTeamYearList() {
		return profitAndLossTeamYearList;
	}

	/**
	 * @param profitAndLossTeamYearList the profitAndLossTeamYearList to set
	 */
	public void setProfitAndLossTeamYearList(List<ManagementInfo> profitAndLossTeamYearList) {
		this.profitAndLossTeamYearList = profitAndLossTeamYearList;
	}

	/**
	 * @return the profitAndLossTeamMonthList
	 */
	public List<ManagementInfo> getProfitAndLossTeamMonthList() {
		return profitAndLossTeamMonthList;
	}

	/**
	 * @param profitAndLossTeamMonthList the profitAndLossTeamMonthList to set
	 */
	public void setProfitAndLossTeamMonthList(List<ManagementInfo> profitAndLossTeamMonthList) {
		this.profitAndLossTeamMonthList = profitAndLossTeamMonthList;
	}

	/**
	 * @return the profitAndLossTeamDateList
	 */
	public List<ManagementInfo> getProfitAndLossTeamDateList() {
		return profitAndLossTeamDateList;
	}

	/**
	 * @param profitAndLossTeamDateList the profitAndLossTeamDateList to set
	 */
	public void setProfitAndLossTeamDateList(List<ManagementInfo> profitAndLossTeamDateList) {
		this.profitAndLossTeamDateList = profitAndLossTeamDateList;
	}

	/**
	 * @return the serialversionuid
	 */
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String execute() throws Exception {
		System.out.println("ProfitAndLossTeamAction================");
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

		try {
			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ManagementService managementService = (ManagementService) wac.getBean("managementService");

			profitAndLossTeamYearList = (List<ManagementInfo>) managementService.getProfitAndLossTeamYear();
			profitAndLossTeamMonthList = (List<ManagementInfo>) managementService.getProfitAndLossTeamMonth();
			profitAndLossTeamDateList = (List<ManagementInfo>) managementService.getProfitAndLossTeamDate();

			request.setAttribute("profitAndLossTeamYearList", profitAndLossTeamYearList);
			request.setAttribute("profitAndLossTeamMonthList", profitAndLossTeamMonthList);
			request.setAttribute("profitAndLossTeamDateList", profitAndLossTeamDateList);
		} catch (Exception e) {
			REQUEST_RESULT = "FALIED";
			e.printStackTrace();
		}
		return REQUEST_RESULT;
	}
}
